package com.socketCopy;

import java.io.*;
import java.net.Socket;
import java.util.Arrays;

public class WriteThread implements Runnable{

    private Socket socket;
    public WriteThread(Socket socket) {
        this.socket = socket;
    }


    @Override
    public void run() {
        try {
            InputStream is = new FileInputStream("/Users/edy/Desktop/file/1.txt");
            int len;
            byte[] bytes = new byte[1024];
            OutputStream os = socket.getOutputStream();
            while ((len = is.read(bytes)) > 0) {
                os.write(bytes,0,len);
            }
            socket.shutdownOutput();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
